//
//  LBView.swift
//  iPhone
//
//  Created by Toj on 7/26/22.
//

import UIKit

public class LBView: UIView {
    var model_: LBModel? {
        didSet {
            imageView.image = UIImage(named: model_?.name ?? "")
            label.text = model_?.name
        }
    }
    
    private lazy var imageView: UIImageView = {
       let view = UIImageView()
        return view
    }()
    
    private lazy var label: UILabel = {
       let view = UILabel()
        view.textAlignment = .center
        view.textColor = .white
        return view
    }()
    
    
    public override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(imageView)
        addSubview(label)
    }
    
    public override func layoutSubviews() {
        super.layoutSubviews()
        
        imageView.frame = bounds
        label.frame = bounds
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension LBView: STEternalProtocol {
    
    var model: STEternalModel? {
        get {
            return model_
        }
        set {
            guard let m = newValue as? LBModel else { return }
            model_ = m
        }
    }
}
